package com.example.mycamerademo

import android.Manifest
import android.content.Intent
import android.widget.Toast
import com.example.mycamerademo.audio.AudioRecorderActivity

import com.example.mycamerademo.cameraxlearing.CameraXMainActivity
import com.example.mycamerademo.databinding.ActivityMainBinding
import com.permissionx.guolindev.PermissionX


class MainActivity : BaseViewBindActivity<ActivityMainBinding>() {


    init {
        //native的 ”库名称“ --CMakeLists.txt中的”库名称“
        System.loadLibrary("mynativecmakelearing")
    }


    //c++方法名称native-make.cpp文件中的
    external fun stringFromJNITGW(): String?

    override fun getLayoutInflateId() = R.layout.activity_main

    override fun initData() {
        requestPermission()
        mBind.startCamera2.setOnClickListener {
            startActivity(Intent(this, CameraXMainActivity::class.java))
        }
        mBind.startAudio.setOnClickListener {
            startActivity(Intent(this, AudioRecorderActivity::class.java))
        }

        //获取c文件的内容
        mBind.btJniText.text = stringFromJNITGW()
    }

    override fun initUI() {

    }


    /**
     * 请求权限
     */
    private fun requestPermission() {
        PermissionX.init(this)
            .permissions(
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.CAMERA,
                Manifest.permission.RECORD_AUDIO,
                Manifest.permission.READ_PHONE_STATE
            )
//            .onForwardToSettings { scope, deniedList ->
//               Toast.makeText(this, "你应该去设置里面开启这些权限：$deniedList",Toast.LENGTH_SHORT).show()
//            }
            .request { allGranted, grantedList, deniedList ->
                if (allGranted) {
                    Toast.makeText(this, "All permissions are granted", Toast.LENGTH_LONG).show()
                } else {
                    Toast.makeText(this, "These permissions are denied: $deniedList", Toast.LENGTH_LONG).show()
                }
            }
    }

}